#!/bin/bash

# 临时禁用IPv6路由广告
echo 0 > /proc/sys/net/ipv6/conf/all/accept_ra 2>/dev/null
echo 0 > /proc/sys/net/ipv6/conf/default/accept_ra 2>/dev/null

# 永久禁用IPv6路由广告
if grep -q "^net.ipv6.conf.all.accept_ra" /etc/sysctl.conf; then
    sed -i 's/^net.ipv6.conf.all.accept_ra.*/net.ipv6.conf.all.accept_ra=0/' /etc/sysctl.conf
else
    echo "net.ipv6.conf.all.accept_ra=0" >> /etc/sysctl.conf
fi

if grep -q "^net.ipv6.conf.default.accept_ra" /etc/sysctl.conf; then
    sed -i 's/^net.ipv6.conf.default.accept_ra.*/net.ipv6.conf.default.accept_ra=0/' /etc/sysctl.conf
else
    echo "net.ipv6.conf.default.accept_ra=0" >> /etc/sysctl.conf
fi

# 应用配置
sysctl -p >/dev/null 2>&1

echo "IPv6路由广告禁用配置完成"